﻿<Window x:Class="RandomFileCopier.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:RandomFileCopier"
        xmlns:extendedToolkit="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
        xmlns:converters="clr-namespace:RandomFileCopier.Converters"
        xmlns:system="clr-namespace:System;assembly=mscorlib"
        xmlns:enums="clr-namespace:RandomFileCopier.Models"
        xmlns:helpers="clr-namespace:RandomFileCopier.Helpers"
        xmlns:controls="clr-namespace:RandomFileCopier.Controls" 
        xmlns:light="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Platform"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        mc:Ignorable="d"
        xmlns:resx="clr-namespace:RandomFileCopier.Properties"
        DataContext="{Binding Source={StaticResource Locator}, Path=MainViewModel}"
        Title="{x:Static resx:Resources.Title}" Height="600" Width="700"
        MinWidth="700"
        MinHeight="600"
        Name="RootWindow">
    <!--Test codeplex main remote-->
    <Window.Resources>
        <helpers:BindingProxy x:Key="proxy" Data="{Binding}"/>
        <converters:EnumToBooleanConverter x:Key="EnumToBoolConverter"/>
        <converters:ValueConverterGroup x:Key="EnumToVisibilityConverter">
            <converters:EnumToBooleanConverter/>
            <BooleanToVisibilityConverter/>
        </converters:ValueConverterGroup>
        <converters:NullToBooleanConverter x:Key="NullToBooleanConverter"/>
        <Thickness x:Key="Margin" Left="0" Top="5" Right="0" Bottom="5" />
        <system:Double x:Key="Height">20</system:Double>
        <converters:MediaTypeVisibilityConverter x:Key="MediaConverter" />
        <converters:IsEqualToDoubleVisibilityConverter Number="0" x:Key="NumberEqualConverter"/>
        <converters:EnumToBooleanConverter x:Key="EnumToBooleanConverter" />
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <converters:InvertedBooleanConverter x:Key="InvertedBooleanConverter"/>
        <converters:ValueConverterGroup x:Key="InvertedBooleanToVisibilityConverter">
            <converters:InvertedBooleanConverter/>
            <BooleanToVisibilityConverter/>
        </converters:ValueConverterGroup>
        <Style TargetType="{x:Type Button}">
            <Setter Property="Padding" Value="4,4,4,4"/>
        </Style>
        <Style TargetType="{x:Type extendedToolkit:CheckComboBox}">
            <Setter Property="Margin" Value="{StaticResource Margin}"/>
        </Style>
        <Style TargetType="{x:Type TextBox}">
            <Setter Property="Margin" Value="{StaticResource Margin}"/>
            <Setter Property="Validation.ErrorTemplate" Value="{StaticResource ErrorTemplateSilverlightStyle}"/>
            <Setter Property="Height" Value="{StaticResource Height}"/>
        </Style>
        <Style TargetType="{x:Type extendedToolkit:DecimalUpDown}">
            <Setter Property="Height" Value="{StaticResource Height}"/>
        </Style>
        <Style TargetType="{x:Type controls:MinMaxControl}">
            <Setter Value="0 2 0 0" Property="Margin"/>
        </Style>
        <DataTemplate x:Key="checkBoxEditorItemTemplate">
            <CheckBox></CheckBox>
        </DataTemplate>
        <Style TargetType="{x:Type controls:CopyDataGrid}">
            <Setter Value="0 8 0 0" Property="Margin"/>
        </Style>
        <Style TargetType="{x:Type Expander}">
            <Setter Property="ContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <ContentControl Content="{Binding}" Margin="25 0 0 0"/>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="IsExpanded" Value="False"/>
            <Setter Property="HeaderTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Grid Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}}, Path=ActualWidth}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <ContentControl Grid.Column="0" Content="{Binding}" FontWeight="Medium"/>
                            <Rectangle Margin="5 0 0 0" VerticalAlignment="Center" Grid.Column="1" Height="1" Fill="Black" />
                        </Grid>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="DataGridTemplates" TargetType="{x:Type ContentControl}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=DataContext.MediaType, ElementName=RootWindow}" Value="{x:Static enums:MediaType.Video}">
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <controls:CopyDataGrid ItemsSource="{Binding CollectionViewSourceItems, Mode=OneWay}" Grid.Row="0">
                                    <DataGrid.Columns>
                                        <DataGridTextColumn IsReadOnly="True" Width="10*" Header="{x:Static resx:Resources.SizeInMB}" Binding="{Binding SizeInMB, StringFormat={}{0:F2}}"/>
                                        <DataGridTextColumn IsReadOnly="True" Width="10*" Header="{x:Static resx:Resources.SizeInGB}" Binding="{Binding SizeInGB, StringFormat={}{0:F2}}" />
                                        <DataGridTextColumn IsReadOnly="True" Width="25*" Header="{x:Static resx:Resources.SubtitlePath}" Binding="{Binding SubtitlePath}"/>
                                    </DataGrid.Columns>
                                </controls:CopyDataGrid>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=DataContext.MediaType, ElementName=RootWindow}" Value="{x:Static enums:MediaType.Audio}">
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <controls:CopyDataGrid ItemsSource="{Binding CollectionViewSourceItems, Mode=OneWay}" Grid.Row="0">
                                    <DataGrid.Columns>
                                        <DataGridTextColumn IsReadOnly="True" Width="10*" Header="{x:Static resx:Resources.SizeInMB}" Binding="{Binding SizeInMB, StringFormat={}{0:F2}}"/>
                                    </DataGrid.Columns>
                                </controls:CopyDataGrid>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=DataContext.MediaType, ElementName=RootWindow}" Value="{x:Static enums:MediaType.Folder}">
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <controls:CopyDataGrid  ItemsSource="{Binding CollectionViewSourceItems, Mode=OneWay}" Grid.Row="0">
                                    <DataGrid.Columns>
                                        <DataGridTextColumn IsReadOnly="True" Width="10*" Header="{x:Static resx:Resources.SizeInMB}" Binding="{Binding SizeInMB, StringFormat={}{0:F2}}"/>
                                        <DataGridTextColumn IsReadOnly="True" Width="10*" Header="{x:Static resx:Resources.SizeInGB}" Binding="{Binding SizeInGB, StringFormat={}{0:F2}}" />
                                    </DataGrid.Columns>
                                </controls:CopyDataGrid>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </DataTrigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="OptionsTemplate" TargetType="{x:Type ContentControl}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=DataContext.MediaType, ElementName=RootWindow}" Value="{x:Static enums:MediaType.Video}">
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <StackPanel>
                                    <Expander Header="{x:Static resx:Resources.SearchOptions}">
                                    <StackPanel>
                                            <extendedToolkit:CheckComboBox SelectedItemsOverride="{Binding Model.SelectedExtensions}" ItemsSource="{Binding Extensions}"/>
                                            <CheckBox Content="{x:Static resx:Resources.IncludeSubtitles}" IsChecked="{Binding Model.IncludeSubtitles}"/>
                                            <CheckBox Content="{x:Static resx:Resources.SearchSubDirectories}" IsChecked="{Binding Model.IncludeSubDirectories}"/>
                                        </StackPanel>
                                    </Expander>
                                    <Expander Header="{x:Static resx:Resources.SelectionOptions}">
                                        <StackPanel>
                                            <CheckBox Command="{Binding RefreshSelectionCommand}" Content="{x:Static resx:Resources.OnlyVideosWithSubtitles}" IsChecked="{Binding SelectionModel.VideosWithSubtitlesOnly}"/>
                                            <CheckBox Command="{Binding RefreshSelectionCommand}" Content="{x:Static resx:Resources.AvoidPreviousCopied}" IsChecked="{Binding SelectionModel.AvoidPreviousCopied}" ToolTip="{x:Static resx:Resources.AvoidPreviousCopiedTooltip}"/>
                                            <controls:MinMaxControl Command="{Binding RefreshSelectionCommand}" MinValue="{Binding SelectionModel.MinimumFileSize}" MaxValue="{Binding SelectionModel.MaximumFileSize}" SizeUnit="{x:Static resx:Resources.GB}" MaxSliderValue="10"/>
                                        </StackPanel>
                                    </Expander>
                                </StackPanel>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=DataContext.MediaType, ElementName=RootWindow}" Value="{x:Static enums:MediaType.Audio}">
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <StackPanel>
                                    <Expander Header="{x:Static resx:Resources.SearchOptions}">
                                        <StackPanel>
                                            <extendedToolkit:CheckComboBox ItemsSource="{Binding Extensions}" SelectedItemsOverride="{Binding Model.SelectedExtensions}"/>
                                            <CheckBox Content="{x:Static resx:Resources.SearchSubDirectories}" IsChecked="{Binding Model.IncludeSubDirectories}"/>
                                        </StackPanel>
                                    </Expander>
                                    <Expander Header="{x:Static resx:Resources.SelectionOptions}">
                                        <StackPanel>
                                            <CheckBox Command="{Binding RefreshSelectionCommand}" Content="{x:Static resx:Resources.AvoidPreviousCopied}" IsChecked="{Binding SelectionModel.AvoidPreviousCopied}" ToolTip="{x:Static resx:Resources.AvoidPreviousCopiedTooltip}"/>
                                            <controls:MinMaxControl  Command="{Binding RefreshSelectionCommand}" MinValue="{Binding SelectionModel.MinimumFileSize}" MaxValue="{Binding SelectionModel.MaximumFileSize}" SizeUnit="{x:Static resx:Resources.MB}" MaxSliderValue="350"/>
                                        </StackPanel>
                                    </Expander>
                                </StackPanel>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=DataContext.MediaType, ElementName=RootWindow}" Value="{x:Static enums:MediaType.Folder}">
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <Expander Header="{x:Static resx:Resources.SelectionOptions}">
                                    <StackPanel>
                                        <CheckBox Command="{Binding RefreshSelectionCommand}" Content="{x:Static resx:Resources.AvoidPreviousCopied}" IsChecked="{Binding SelectionModel.AvoidPreviousCopied}" ToolTip="{x:Static resx:Resources.AvoidPreviousCopiedTooltip}"/>
                                        <controls:MinMaxControl  Command="{Binding RefreshSelectionCommand}" MinValue="{Binding SelectionModel.MinimumFileSize}" MaxValue="{Binding SelectionModel.MaximumFileSize}" SizeUnit="{x:Static resx:Resources.GB}" MaxSliderValue="100"/>
                                    </StackPanel>
                                </Expander>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Grid Margin="10, 10, 10, 10" DataContext="{Binding ViewModel}" >
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <!--Source-->
        <Grid Name="SourceGrid" Grid.Row="0" IsEnabled="{Binding IsBusyCopying, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource InvertedBooleanConverter}}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid Grid.Row="0">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <StackPanel Grid.Row="0" Orientation="Horizontal" Margin="{StaticResource Margin}">
                            <StackPanel.Resources>
                                <Style TargetType="{x:Type RadioButton}">
                                    <Setter Property="Margin" Value="0 0 5 0"/>
                                </Style>
                            </StackPanel.Resources>
                            <RadioButton GroupName="MediaType" IsChecked="{Binding Path=DataContext.MediaType, ElementName=RootWindow, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter={x:Static enums:MediaType.Video}}" Content="{x:Static resx:Resources.VideoFileTypes}"/>
                            <RadioButton GroupName="MediaType" IsChecked="{Binding Path=DataContext.MediaType, ElementName=RootWindow, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter={x:Static enums:MediaType.Audio}}"  Content="{x:Static resx:Resources.AudioFileTypes}"/>
                            <RadioButton GroupName="MediaType" IsChecked="{Binding Path=DataContext.MediaType, ElementName=RootWindow, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter={x:Static enums:MediaType.Folder}}"  Content="{x:Static resx:Resources.FolderFileTypes}"/>
                        </StackPanel>
                        <Button Grid.Row="1"  Content="{x:Static resx:Resources.BrowseSource}" HorizontalAlignment="Left" VerticalAlignment="Center" Command="{Binding BrowseSourceCommand}"/>
                        <StackPanel Grid.Row="2">
                            <TextBox  Text="{Binding Model.SourcePath, NotifyOnValidationError=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" IsEnabled="True"/>
                            <ContentControl Content="{Binding}" Style="{StaticResource OptionsTemplate}"/>
                        </StackPanel>
                    </Grid>
                </Grid>
            </Grid>
        </Grid>
        <!--Destination-->
        <Grid Grid.Row="1" IsEnabled="{Binding IsEnabled, ElementName=SourceGrid}"  >
            
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Button Margin="0 5 0 0" Content="{x:Static resx:Resources.BrowseDestination}" HorizontalAlignment="Left" VerticalAlignment="Center" Command="{Binding BrowseDestinationCommand}"/>
                <StackPanel Grid.Row="1">
                    <TextBox  Text="{Binding Model.DestinationPath, NotifyOnValidationError=True, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" IsEnabled="True"/>
                    <Grid Visibility="{Binding Model.MaxDestinationSize, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource NumberEqualConverter}}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Slider Margin="0 5 0 0"  Value="{Binding SelectionModel.SelectedSize, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=False, ValidatesOnNotifyDataErrors=False}" Grid.Column="0" IsSnapToTickEnabled="True" TickFrequency="0.1" Minimum="0.1" Maximum="{Binding Model.MaxDestinationSize, UpdateSourceTrigger=PropertyChanged}">
                            
                            <i:Interaction.Triggers>
                                <helpers:RoutedEventTrigger RoutedEvent="Thumb.DragCompleted">
                                    <light:EventToCommand Command="{Binding Mode=OneWay, Path=SliderDragCompletedCommand}"/>
                                </helpers:RoutedEventTrigger>
                                <helpers:RoutedEventTrigger RoutedEvent="Thumb.DragStarted">
                                    <light:EventToCommand Command="{Binding Mode=OneWay, Path=SliderDragStartedCommand}"/>
                                </helpers:RoutedEventTrigger>
                                <i:EventTrigger EventName="ValueChanged">
                                    <light:EventToCommand Command="{Binding Mode=OneWay, Path=SliderValueChangedCommand}"/>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </Slider>
                        <extendedToolkit:DecimalUpDown Margin="5 0 0 0" AllowSpin="False" ShowButtonSpinner="False" Value="{Binding SelectionModel.SelectedSize,UpdateSourceTrigger=PropertyChanged,StringFormat={}{0:0.##}}" Increment="0.1" Grid.Column="1" Width="100" Minimum="0" Maximum="{Binding Model.MaxDestinationSize, UpdateSourceTrigger=PropertyChanged}" FormatString="F1"/>
                        <Label Grid.Column="2">GB</Label>
                    </Grid>
                </StackPanel>
                <extendedToolkit:BusyIndicator BusyContent="{x:Static resx:Resources.PleaseWait}" Grid.Row="2" IsBusy="{Binding IsBusySearching}">
                    <Grid Name="parentGrid">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <ContentControl Content="{Binding}" Grid.Row="0" Style="{StaticResource DataGridTemplates}"/>
                        <Grid Grid.Row="1" >
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Label Grid.Column="0" HorizontalAlignment="Left" Content="{Binding SelectedFilesCount }" ContentStringFormat="{x:Static resx:Resources.TotalFilesSelected}"/>
                            <Label Grid.Column="1" Foreground="{Binding SelectedSizeColor}" HorizontalAlignment="Right" Content="{Binding TotalSelectedSize}" ContentStringFormat="{x:Static resx:Resources.TotalSelectedSize}"/>
                            <Label Grid.Column="2" HorizontalAlignment="Right" Content="{Binding CollectionViewSourceItems.Count}" ContentStringFormat="{x:Static resx:Resources.TotalFilesFound}"/>
                        </Grid>
                    </Grid>
                </extendedToolkit:BusyIndicator>
            </Grid>
        </Grid>
        <Button Grid.Row="2" Visibility="{Binding IsBusySearching, Converter={StaticResource InvertedBooleanToVisibilityConverter}}"  Command="{Binding FindFilesCommand}" Margin="{StaticResource Margin}"  Content="{x:Static resx:Resources.FindFiles}" />
        <Button Grid.Row="2" Visibility="{Binding IsBusySearching, Converter={StaticResource BooleanToVisibilityConverter}}" Command="{Binding CancelFindFilesCommand}" Margin="{StaticResource Margin}"  Content="{x:Static resx:Resources.Cancel}" />
        <Button Grid.Row="3" Visibility="{Binding IsBusyCopying, Converter={StaticResource InvertedBooleanToVisibilityConverter}}" Content="{x:Static resx:Resources.StartCopy}"  Command="{Binding CopyCommand}"/>
        <Grid Grid.Row="3" Visibility="{Binding IsBusyCopying, Converter={StaticResource BooleanToVisibilityConverter}}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Button Grid.Row="0"  Content="{x:Static resx:Resources.Cancel}"  Command="{Binding CancelCopyCommand}"/>
            <!--Ugly but simple and does work progressbar and textblock overlay eachother and everything looks nice--> 
            <ProgressBar Name="copyProgressBar" Margin="0 5 0 0" Grid.Row="1" Height="20" IsIndeterminate="True"/>
            <TextBlock Margin="{Binding Margin, ElementName=copyProgressBar}" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center">
                <TextBlock.Text>
                    <MultiBinding StringFormat="{x:Static resx:Resources.ProcessingFiles}">
                        <Binding Path="Progress"/>
                        <Binding Path="MaxProgressBarValue"/>
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
        </Grid>
    </Grid>
</Window>
